#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>

int main(int argc, char const *argv[])
{
    int fdSrc = open("01_open.c", O_RDONLY);
    if ( -1 == fdSrc )
    {
        perror("Fail open");
        return -1;
    }
    printf("fdSrc = %d\n", fdSrc);

    char strBuff[200] = {0};
    FILE *fpSrc = fdopen(fdSrc, "r");
    assert( fpSrc != NULL );
    fgets(strBuff, sizeof(strBuff), fpSrc);
    printf("%s", strBuff);

    fclose(fpSrc);
    
    return 0;
}

/*
系统函数open打开文件获取文件描述符
标准函数fdopen根据文件描述符打开文件流

*/